<template>
	<div class="setting">
		<!-- 工具栏 -->
		<Toolbar>
			<template #right>
				<div class="right-item">
					<el-button
						size="small"
						type="info"
						@click="(title = '新增配置'), (showdialog_add = true)"
					>
						新增灾情
					</el-button>
				</div>
			</template>
		</Toolbar>

		<!-- 表格展示 -->
		<div class="table mt15">
			<el-table :data="tableData" border style="width: 100%">
				<el-table-column type="selection" align="center"></el-table-column>
				<el-table-column type="index" align="center" label="序号" width="60"></el-table-column>
				<el-table-column align="center" prop="prop" label="案件类型"></el-table-column>
				<el-table-column align="center" prop="prop" label="灾情类型"></el-table-column>
				<el-table-column align="center" prop="prop" label="案发时间"></el-table-column>
				<el-table-column align="center" prop="prop" label="灾情位置"></el-table-column>
				<el-table-column align="center" label="操作" width="160">
					<template #default="{ row }">
						<el-button type="text" size="mini" @click="edit(row)">编辑</el-button>
						<el-button type="text" size="mini" @click="Delete(row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>

		<!-- 翻页 -->
		<div class="switchTable">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page="searchInfo.pageNum"
				:page-size="searchInfo.pageSize"
				:page-sizes="[10, 20, 50]"
				:total="totalPage"
				background
				layout="sizes, prev, pager, next, jumper"
			></el-pagination>
		</div>

		<!-- 新增灾情 -->
		<el-dialog :title="title" :visible.sync="showdialog_add" width="600px">
			<div>
				<el-form
					:model="ruleForm"
					label-position="left"
					:rules="rules"
					ref="ruleForm"
					label-width="80px"
					class="demo-ruleForm"
				>
					<el-form-item label="主管单位" prop="name">
						<el-select style="width: 100%" v-model="ruleForm.type" placeholder="请选择">
							<el-option
								v-for="item in select_type"
								:key="item.value"
								:label="item.label"
								:value="item.value"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="管辖单位" prop="name">
						<el-select style="width: 100%" v-model="ruleForm.type" placeholder="请选择">
							<el-option
								v-for="item in select_type"
								:key="item.value"
								:label="item.label"
								:value="item.value"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="单位位置" prop="name">
						<el-input disabled v-model="ruleForm.address" placeholder="请选择">
							<i @click="openMap" slot="suffix" class="el-input__icon el-icon-location"></i>
						</el-input>
					</el-form-item>
				</el-form>
			</div>
			<div slot="footer">
				<el-button type="primary" @click="showdialog_add = false">确 定</el-button>
			</div>
		</el-dialog>

		<!-- 地图弹窗 -->
		<el-dialog append-to-body :visible.sync="showdialog_map" width="80%">
			<div style="height: 500px">
				<XyMap @change="changePoint" :lnglat="lnglat" />
			</div>
		</el-dialog>
	</div>
</template>
 
<script>
import XyMap from '@/components/xy-map.vue';
import { turnPage } from '@/mixins/turnPage';

export default {
	mixins: [turnPage],
	name: 'Setting',
	components: {
		XyMap
	},
	data() {
		return {
			showdialog_add: false /* 新增弹窗 */,
			showdialog_map: false /* 地图弹窗 */,
			tableData: [{}] /* 表格数据 */,
			totalPage: 1 /* 表格总数 */,
			ruleForm: {} /* 表单 */,
			rules: {} /* 表单校验规则 */,
			select_type: [] /* 灾情类型下拉 */,
			searchInfo: {
				pageNum: 1,
				pageSize: 10
			} /* 检索信息 */,
			title: '新增灾情',
			lnglat: []
		};
	},
	created() {
		this.init();
	},
	methods: {
		// 初始化
		init() {},

		// 查询表格数据
		queryTable() {},

		// 编辑
		edit(row) {
			this.title = '编辑灾情';
			this.showdialog_add = true;
		},

		// 打开地图
		openMap() {
			this.showdialog_map = true;
		},

		// 地图点位改变
		changePoint(mapInfo) {
			this.ruleForm.address = mapInfo.address;
			this.lnglat = [mapInfo.lng, mapInfo.lat];
		},

		// 详情
		Delete(row) {}
	}
};
</script>
 
<style lang="scss">
.setting {
	padding: 20px;
	font-size: 14px;

	.left-item {
		& > span {
			font-size: 13px;
			color: #666;
			margin-right: 5px;
		}

		.el-select {
			margin-right: 20px;
		}
	}

	.switchTable {
		display: flex;
		justify-content: flex-end;
		margin-top: 15px;
	}

	.el-dialog {
		margin-top: 8vh !important;
	}

	.el-dialog__footer {
		padding-top: 0;
	}

	.el-icon-location {
		width: 30px;
		cursor: pointer !important;
	}
}
</style>